@extends('admin::layouts.master')

@section('title', __('MultiSeller::seller_group.title'))

@section('content')
@if ($errors->has('error'))
<x-seller-alert type="danger" msg="{{ $errors->first('error') }}" class="mt-4" />
@endif

@if (session()->has('success'))
<x-seller-alert type="success" msg="{{ session('success') }}" class="mt-4" />
@endif
  <div class="card">
    <div class="card-body">
      <div class="d-flex justify-content-between mb-4">
        <a href="{{ admin_route('seller_groups.create') }}" class="btn btn-primary">{{ __('MultiSeller::common.create') }}</a>
      </div>

      @if ($seller_groups->count())
        <div class="table-push">
          <table class="table">
            <thead>
              <tr>
                <th>{{ __('MultiSeller::seller.id') }}</th>
                <th>{{ __('MultiSeller::seller_group.name') }}</th>
                <th>{{ __('MultiSeller::seller_group.fee_sale_flat') }}</th>
                <th>{{ __('MultiSeller::seller_group.fee_sale_percent') }}</th>
                <th>{{ __('common.created_at') }}</th>
                <th>{{ __('common.action') }}</th>
              </tr>
            </thead>
            <tbody>
              @foreach ($seller_groups as $seller_group)
              <tr data-item='@json($seller_group)'>
                <td>{{ $seller_group['id'] }}</td>
                <td>{{ $seller_group->description['name'] }}</td>
                <td>{{ $seller_group->fee_sale_flat }}</td>
                <td>{{ $seller_group->fee_sale_percent }}%</td>
                <td>{{ $seller_group['created_at'] }}</td>
                <td>
                  <a class="btn btn-outline-secondary btn-sm" href="{{ admin_route('seller_groups.edit', [$seller_group->id]) }}">{{ __('common.edit') }}</a>
                  <button class="btn btn-outline-danger delete-btn btn-sm ml-1" type="button" data-id="{{ $seller_group->id }}">{{ __('common.delete') }}</button>
                </td>
              </tr>
              @endforeach
            </tbody>
          </table>
        </div>
      @else
        <x-admin-no-data />
      @endif
    </div>
  </div>
@endsection

@push('footer')
<script>
  $('.delete-btn').click(function(event) {
    const id = $(this).data('id');
    const self = $(this);

    layer.confirm('{{ __('common.confirm_delete') }}', {
      title: "{{ __('common.text_hint') }}",
      btn: ['{{ __('common.cancel') }}', '{{ __('common.confirm') }}'],
      area: ['400px'],
      btn2: () => {
        $http.delete(`seller_groups/${id}`).then((res) => {
          layer.msg(res.message);
          window.location.reload();
        })
      }
    })
  });
</script>
@endpush